﻿Imports BUS

Public Class frmDangNhapPM

    Private Function KTNhapThongTin() As Boolean
        If txtUserName.Text.Trim = "" Or txtPassWord.Text.Trim = "" Then
            If txtUserName.Text.Trim = "" Then
                txtUserName.Focus()
            Else
                txtPassWord.Focus()
            End If
            Return False
        End If
        Return True
    End Function

    Private Sub frmDangNhapPM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ProcFuncBus.CreateConnectionStringFromXml(Application.StartupPath + "\InfoDataBaseServer.xml")
    End Sub

    Private Sub frmDangNhapPM_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Application.Exit()
    End Sub

    Private Sub btnSignOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSignOut.Click
        Application.Exit()
    End Sub

    Private Sub txtUserName_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUserName.KeyDown
        If e.KeyValue = 13 Then
            txtPassWord.Focus()
        Else
            Return
        End If
    End Sub

    Private Sub txtPassWord_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassWord.KeyDown
        If e.KeyValue = 13 Then
            btnSignIn.Focus()
        Else
            Return
        End If
    End Sub

    Private Sub btnSignIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSignIn.Click
        If KTNhapThongTin() = False Then
            MessageBox.Show("Xin vui long nhap du thong tin", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Else
            Dim sql = "select count(username) from DangNhap where username = '" & txtUserName.Text.Trim & "' and pass = '" & txtPassWord.Text.Trim & "'"
            Dim count = CType(ProcFuncBus.ExecuteFuncSSQL(sql), Int32)
            If count = 0 Then
                MessageBox.Show("Thong tin dang nhap sai. Xin vui long nhap lai", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                Me.Hide()
                Dim frm As New frmQuanLy
                frm.ShowDialog()
            End If
        End If
        Return
    End Sub


End Class